/*
 * Content.fx
 *
 * Created on 27-May-2010, 14:05:13
 */

package com.googlecode.snorkel;

import javafx.scene.CustomNode;
import javafx.scene.Node;
import javafx.scene.Group;
import javafx.scene.shape.Rectangle;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.scene.text.Font;
import javafx.scene.effect.DropShadow;
import javafx.scene.image.ImageView;
import javafx.scene.image.Image;
import javafx.animation.Timeline;
import javafx.animation.KeyFrame;
import javafx.animation.Interpolator;

/**
 * @author brian
 */

public class Content extends CustomNode {
   // Set the initial opacity level
   var opacityState = 0.0;

   // Set some initial values, mostly for testing purposes
   var socialNetwork = 'SNorkel';
   var icon = '{__DIR__}images/SNorkel_icon_1.png';
   var quickText = 'SNorkel';

   // Create our initial content Group and set the default value
   var content = Group{
      content: [
         Rectangle {
            x: 100, y: 200
            width: 253, height: 120
            fill: Color.WHITE
            stroke: Color.GRAY
            strokeWidth: 3.0
            arcWidth: 20
            arcHeight: 20
            smooth: true
//            onMousePressed: function (e: MouseEvent): Void {
//               // just to prove how easy it is to integrate Java code
//               var facebookConnect = FacebookDummy {}
//               facebookConnect.doLogin();
//            }
         }
         Text {
            x: 120, y: 230
            font: Font {size: 22}
            content: bind quickText
            fill: Color.BLACK
            effect: DropShadow {
               offsetX: 5
               offsetY: 5
               color: Color.BLACK
               radius: 8
            }
         }
         ImageView {
            image: Image {url: '{__DIR__}images/SNorkel_icon_1.png'}
            x: 140
            y: 250
            fitWidth: 60.0
            fitHeight: 60.0
         }
      ]
   };


   function createContent(){
      // Much more to be added into these to make the real content!
      if(socialNetwork == 'SNorkel'){ quickText = 'This is SNorkel'; }
      else if (socialNetwork == 'Bebo'){ quickText = 'This is Bebo'; }
      else if (socialNetwork == 'Twitter'){ quickText = 'This is Twitter'; }
      else if (socialNetwork == 'Facebook'){ quickText = 'This is Facebook'; }
      else if (socialNetwork == 'MySpace'){ quickText = 'This is MySpace'; }
      else if (socialNetwork == 'YouTube'){ quickText = 'This is YouTube'; }
      else if (socialNetwork == 'Flickr'){ quickText = 'This is Flickr'; }
      else if (socialNetwork == 'Picasa'){ quickText = 'This is Picasa'; }
      else if (socialNetwork == 'LinkedIn'){ quickText = 'This is LinkedIn'; }
      else if (socialNetwork == 'Settings'){ quickText = 'This is Settings'; }
   }

   // Make it possible to change content
   package function setSocialNetwork(sn:String){
      socialNetwork = sn;
      fadeOut.playFromStart();
      createContent();
      fadeIn.playFromStart();
   }

   // Add the fading and public functions
   var fadeIn = Timeline {
      keyFrames : [
         KeyFrame {
            time: 2s
            values: [opacityState => 1.0 tween Interpolator.LINEAR]
         }
      ]
   }
   var fadeOut = Timeline {
      keyFrames : [
         KeyFrame {
            time: 2s
            values: [opacityState => 0.0 tween Interpolator.LINEAR]
         }
      ]
   }
   package function fadeInContent(){fadeIn.playFromStart();}
   package function fadeOutContent(){fadeOut.playFromStart();}

   override public function create(): Node {
      createContent();
      Group {
         content: [content]
         opacity: bind opacityState
      };
   }
}
